<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/static/img/favicon.ico">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">菜单名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" value="{{ menu.name or '' }}" required lay-verify="required"
                           placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单路径</label>
                <div class="layui-input-inline">
                    <input type="text" name="url" value="{{ menu.url or '' }}"
                           placeholder="请输入菜单路径" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="0" title="目录" {% if action == 'add' and parentId != '0' %} disabled {% endif %} {% if parentId == '0' or menu.type == 0 %} checked {% endif %}>
                    <input type="radio" name="type" value="1" title="菜单" {% if action == 'add' and parentId == '0' %} disabled {% endif %} {% if parentId != '0' or menu.type == 1 %} checked {% endif %}>
                    <input type="radio" name="type" value="2" title="按钮" {% if action == 'add' and parentId == '0' %} disabled {% endif %} {% if menu.type == 2 %} checked {% endif %}>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="text" name="order" value="{{ menu.order or 1 }}" required lay-verify="required"
                           placeholder="请输入排序号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" id="statusId" name="status" value="1" lay-skin="switch" lay-filter="status"
                    {% if menu is none or menu.status == 1 %} checked {% endif %}>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-demo="getChecked" lay-submit="" lay-filter="add">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>

    layui.config({
        base: "/static/js/"
    }).use(['form', 'common'], function () {
        var $ = layui.jquery;
        var form = layui.form,
            common = layui.common;

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            }
        });

        //监听开关
        form.on('switch(status)', function () {
            if (this.checked) {
                $("#statusId").val("1");
            } else {
                $("#statusId").val("0");
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            //发异步，把数据提交
            var url = "/admin/menu/{{ action }}/{{ menu.id or 0 }}";
            var param = data.field;
            common.ajaxFormCms('post', 'false', url, param);

            //关闭当前frame
            xadmin.close();
            // 可以对父窗口进行刷新
            xadmin.father_reload();
            return false;
        });

    });
</script>

</body>
</html>
